using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace Nojin.Deployment
{
    /// <summary>
    /// Contains general information for each new update.
    /// </summary>
    public class UpdateInfo
    {
        #region Constructors

        /// <summary>
        /// Constructs a new <seealso cref="UpdateInfo"/> object.
        /// </summary>
        public UpdateInfo()
        {
        }

        /// <summary>
        /// Constructs a new <seealso cref="UpdateInfo"/> object and initialize it properties.
        /// </summary>
        /// <param name="name">Name of update.</param>
        /// <param name="description">A text descriping the update.</param>
        /// <param name="version">Application's new version after update.</param>
        /// <param name="releaseDate">Date which application updated.</param>
        /// <param name="packageSize">Size of files to be downloaded to client.</param>
        /// <param name="arbitary">To warn user abour critical updates.</param>
        /// <param name="manifestPath">Path to the manifest file which defines download list.</param>
        /// <param name="changeLogFilePath">Path to change log(release note) file.</param>
        /// <param name="silentUpdate"></param>
        public UpdateInfo(string name, string description, Version version, DateTime releaseDate, long packageSize, bool arbitary, string manifestPath, string changeLogFilePath,bool silentUpdate)
        {
            this.name = name;
            this.description = description;
            this.version = version;
            this.releaseDate = releaseDate;
            this.packageSize = packageSize;
            this.arbitary = arbitary;
            this.manifestPath = manifestPath;
            this.changeLogFilePath = changeLogFilePath;
            this.silentUpdate = silentUpdate;
        }
        
        #endregion

        #region Properties
        private string name;
        /// <summary>
        /// Name of update.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string description;
        /// <summary>
        /// A text descriping the update.
        /// </summary>
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }
        
        private Version version;
        /// <summary>
        /// Application's new version after update.
        /// </summary>
        [XmlIgnore]        
        public Version Version
        {
            get { return version; }
            set { version = value; }
        }

        /// <summary>
        /// This dummy property just provided for simplifing service programming.
        /// Do not bother yourself about it.
        /// </summary>
        public string VersionText
        {
            get { return version.ToString(); }
            set { this.version = new Version(value); }
        }
        
        private long packageSize;
        /// <summary>
        /// Size of files to be downloaded to client.        
        /// </summary>
        public long PackageSize
        {
            get { return packageSize; }
            set { packageSize = value; }
        }
        
        private string manifestPath;
        /// <summary>
        /// Path to the manifest file which defines download list.
        /// The path must be available in user's network.
        /// </summary>
        public string ManifestPath
        {
            get { return manifestPath; }
            set { manifestPath = value; }
        }
        
        private string changeLogFilePath;
        /// <summary>
        /// Path to change log(release note) file.
        /// The path must be available in user's network.
        /// </summary>
        public string ChangeLogFilePath
        {
            get { return changeLogFilePath; }
            set { changeLogFilePath = value; }
        }
        
        private bool arbitary;
        /// <summary>
        /// To warn user abour critical updates.
        /// </summary>
        public bool Arbitary
        {
            get { return arbitary; }
            set { arbitary = value; }
        }
        
        private DateTime? releaseDate;
        /// <summary>
        /// Date which application updated.
        /// </summary>
        public DateTime? ReleaseDate
        {
            get { return releaseDate; }
            set { releaseDate = value; }
        }

        bool silentUpdate;
        /// <summary>
        /// A silent update will be downloaded autonomously witout user awarness.
        /// Please be polite, dont use it for huge download ;-) 
        /// </summary>
        public bool SilentUpdate
        {
            get
            {
                return silentUpdate;
            }
            set
            {
                silentUpdate = value;
            }
        }
        #endregion
    }

    /// <summary>
    /// This dummy class just provided for simplifing service programming.
    /// Do not bother yourself about it.
    /// </summary>
    public class UpdateInfoProxy
    {
        #region Properties

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string description;
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }

        private string version;
        public string Version
        {
            get { return version; }
            set { version = value; }
        }

        private long packageSize;
        public long PackageSize
        {
            get { return packageSize; }
            set { packageSize = value; }
        }

        private string manifestPath;
        public string ManifestPath
        {
            get { return manifestPath; }
            set { manifestPath = value; }
        }

        private string changeLogFilePath;
        public string ChangeLogFilePath
        {
            get { return changeLogFilePath; }
            set { changeLogFilePath = value; }
        }

        private bool arbitary;
        public bool Arbitary
        {
            get { return arbitary; }
            set { arbitary = value; }
        }

        private DateTime? releaseDate;
        public DateTime? ReleaseDate
        {
            get { return releaseDate; }
            set { releaseDate = value; }
        }

        bool silentUpdate;
        public bool SilentUpdate
        {
            get
            {
                return silentUpdate;
            }
            set
            {
                silentUpdate = value;
            }
        }

        #endregion

        #region Methods
        public UpdateInfo Convert()
        {
            UpdateInfo result = new UpdateInfo();
            result.Name = this.name;
            result.Description = this.description;
            result.Version = new Version(this.version);
            result.PackageSize = this.packageSize;
            result.ManifestPath = this.manifestPath;
            result.ChangeLogFilePath = this.changeLogFilePath;
            result.Arbitary = this.arbitary;
            result.ReleaseDate = this.releaseDate;
            result.SilentUpdate = this.silentUpdate;
            return result;
        }  
        #endregion
    }

}

